<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Role extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model($this->session->userdata('formodel'));
		$this->load->model('wus');
		$this->load->library('upload');
		$this->load->library('variable');

	}

	public function index(){

		 $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));

	    $this->load->view($this->session->userdata('formain'));

	    $this->load->view('layouts/footer');

	}

	public function addRole(){
		$role_company = $this->input->post('role_company');
		$role_name = $this->input->post('role_name');
		$role_desc = $this->input->post('role_description');
		$role_status = $this->input->post('role_status');
		
		$data = array(
			':p_role_name'		=> $role_name,
	        ':p_description'	=> $role_desc,
	        ':p_company_id'		=> $this->session->userdata('company_id'),
	        ':p_enable_flag'	=> ( $role_status != "" ? "Y" : "N") ,
	        ':p_created_by'		=> $this->session->userdata('user_id')
		);

		$query = $this->wus->insertRoleData($data);
		echo json_encode($query);

	}

	public function editRole(){
		$role_company = $this->input->post('role_company_e');
		$role_name    = $this->input->post('role_name_e');
		$role_desc    = $this->input->post('role_description_e');
		$role_id  	  = $this->input->post('role_id');
		$role_status  = $this->input->post('role_status_e');	
		
		$data = array(
			':p_role_name'		=> $role_name,
	        ':p_description'	=> $role_desc,
	        ':p_enable_flag'	=> ( $role_status != "" ? "Y" : "N") ,
	        ':p_created_by'		=> $this->session->userdata('user_id'),
	        ':p_role_id'		=> $role_id
		);

		$query = $this->role_model->updateRoleData($data);
		echo json_encode($query);

	}

	public function searchRole(){
		$name = filter_var($this->input->post('role_name_s'),FILTER_SANITIZE_STRING);
		$desc = filter_var($this->input->post('role_description_s'),FILTER_SANITIZE_STRING);
		$query = $this->role_model->search_role($name,$desc);
		echo json_encode($query);
	}

	public function getFormFunctionNames(){
		$value = $this->input->post('type-value');
		$query = $this->wus->getFormFunctionName($value);
		echo json_encode($query);
	}

	public function getModuleList(){
		$value = $this->input->post('type-value');
		$query = $this->wus->getModuleList($value);
		echo json_encode($query);
	}

	public function getMenuList(){
		$value = $this->input->post('type-value');
		$query = $this->wus->getMenuList($value );
		echo json_encode($query);
	}

	public function addRoleDtl(){

		$data = array(
			':p_role_id'   		=> $this->input->post('role_id'),
			':p_form_id' 		=> $this->input->post('form_name_a'),
			':p_allow_create'	=> ($this->input->post('create_cb') != "" ? "Y" : "N"),
			':p_allow_update'	=> ($this->input->post('update_cb') != "" ? "Y" : "N"),
			':p_allow_delete' 	=> ($this->input->post('delete_cb') != "" ? "Y" : "N"),
			':p_read_only' 		=> ($this->input->post('readonly_cb') != "" ? "Y" : "N"),
			':p_enable_flag'	=> ($this->input->post('ena_cb') != "" ? "Y" : "N"),
			':p_created_by'		=> $this->session->userdata('user_id')
		);
		
		$query = $this->role_model->insertRoleDtl($data);
		echo json_encode($query);
	}

	public function getRoleDtl(){

		$query = $this->role_model->getRoleDtl($this->input->post('role_id'));
		echo json_encode($query);
	}

	public function delRoleDtl(){
		$data = array(
			':p_role_id'		=> $this->input->post('role_id'),
			':p_form_id'	    => $this->input->post('form_id')
		);
		$query = $this->role_model->delRoleDtl($data);
		echo json_encode($query);
	}

	public function editRoleDtl(){

		$data = array(
		':p_role_id'		=> $this->input->post('role_id_e'),
		':p_form_id'		=> $this->input->post('form_id_e'),
		':p_allow_create'	=> ($this->input->post('create_cb_e') != "" ? "Y" : "N"),
		':p_allow_update'	=> ($this->input->post('update_cb_e') != "" ? "Y" : "N"),
		':p_allow_delete' 	=> ($this->input->post('delete_cb_e') != "" ? "Y" : "N"),
		':p_read_only' 		=> ($this->input->post('readonly_cb_e') != "" ? "Y" : "N"),
		':p_enable_flag'	=> ($this->input->post('ena_cb_e') != "" ? "Y" : "N"),
		':p_updated_by'	    => $this->session->userdata('user_id')		
		);
		
		$query = $this->role_model->updateRoleDtl($data);
		echo json_encode($query);

	}

	public function add_form(){
		$this->load->view($this->session->userdata('foradd'));
	}

	public function edit_form($id){
		$query = $this->role_model->getROleData($id);
		$this->load->view($this->session->userdata('foredit'),array(
				'role_data' => $query
			));
	}
	public function view_form($id){
		$query = $this->role_model->getROleData($id);
		$this->load->view($this->session->userdata('forview'),array(
				'role_data' => $query
			));
	}

	public function getRoleCb(){
		$query = $this->role_model->getRoleCB($this->input->post('role_id'),$this->input->post('form_id'));
		echo json_encode($query);
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */